<?php 
	Class destination extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('model_destination');	
		}	
		
		public function index(){
			$data['data']=$this->model_destination->listall(20000,0);
			if(isset($_GET['id'])){
				$data['detail']	=$this->model_destination->getdata(intval($_GET['id']));				
			}else $data['detail']=NULL;
			$data['template']='destination/destination';
			$this->load->view('layout',$data);	
		}
		
		public function insert(){
			$data['name']=$_POST['name'];			
			$data['description']=$_POST['description'];	
			//$data['avatar']=$_POST['fuavatar1'];
			//$data['avatar2']=$_POST['fuavatar2'];
			$data['address']=$_POST['address'];
			$data['pathofimage']=$_POST['pathofimage'];
			$data['overview']=$_POST['overview'];
			$data['pricemin']=$_POST['pricemin'];
			$data['pricemax']=$_POST['pricemax'];
			$data['category']=$_POST['category'];
			$data['promotion']=$_POST['promotion'];
			$data['whoust']=$_POST['whoust'];
			$data['detail']=$_POST['detail'];
			$data['provide']=$_POST['provide'];
			$data['status']=$_POST['status'];
			
			$this->model_destination->add($data);
			redirect('/admin/destination/index','refresh');
		}
		
		public function update(){
			if(isset($_GET["id"])){
				$data['name']=$_POST['name'];			
				$data['description']=$_POST['description'];	
				//$data['avatar']=$_POST['fuavatar1'];
				//$data['avatar2']=$_POST['fuavatar2'];
				$data['address']=$_POST['address'];
				$data['pathofimage']=$_POST['pathofimage'];
				$data['overview']=$_POST['overview'];
				$data['pricemin']=$_POST['pricemin'];
				$data['pricemax']=$_POST['pricemax'];
				$data['category']=$_POST['category'];
				$data['promotion']=$_POST['promotion'];
				$data['whoust']=$_POST['whoust'];
				$data['detail']=$_POST['detail'];
				$data['provide']=$_POST['provide'];
				$data['status']=$_POST['status'];
				
				$this->model_destination->update($data,intval($_GET['id']));
				redirect('/admin/destination/index','refresh');
			}	
		}
		
		public function delete(){
			if(isset($_GET["id"])){
				$this->model_destination->del(intval($_GET['id']));	
				redirect('/admin/destination/index','refresh');
			}	
		}
		
		public function changestatus(){			
			if(isset($_GET["id"])){		
				$data=$this->model_destination->getdata(intval($_GET["id"]));								
				if(count($data)>0){
					if(isset($_GET["status"])){
						$data['status']=intval($_GET['status']);
						$this->model_destination->update($data,intval($_GET["id"]));
						redirect('/admin/destination/index','refresh');
					}
				}
			}
		}
	}
?>